<?php

$container_bl=join('&nbsp;', $form->_button_container['BL']);
$container_br=join('&nbsp;', $form->_button_container['BR']);
$container_tr=join('&nbsp;', $form->_button_container['TR']);

if ($form->_status=='delete' || $form->_action=='delete' || $form->_status=='unknow_record'):
	echo $form->output;
else:

if(isset($form->error_string)) echo '<div class="alert">'.$form->error_string.'</div>';
echo $form_scripts;
echo $form_begin;


$tcambio=$form->cambio->value;
$tmoneda=$form->moneda->value;

if($form->_status!='show'){ ?>

<script language="javascript" type="text/javascript">

$(function(){
	$(".inputnum").numeric(".");
	//totalizar();
});
</script>
<?php } ?>
<form id="form" name="form" >
<table align='center' width="90%" style='background: #EEEEEE'>
	<tr>
		<?php if ($form->_status=='show') { ?>
		<td>
		<a href="#" onClick="window.open('<?php echo base_url() ?>formatos/verhtml/PAGO/<?php echo $form->tipo2->value ?>/<?php echo $form->serie->value ?>/<?php echo $form->numero->value ?>', '_blank', 'width=800, height=600, scrollbars=Yes, status=Yes, resizable=Yes, screenx='+((screen.availWidth/2)-400)+',screeny='+((screen.availHeight/2)-300)+'');" heigth="600" >
		<img src='<?php echo base_url() ?>images/html_icon.gif'></a>
		<a href="#" onClick="window.open('<?php echo base_url() ?>formatos/ver/PAGO/<?php echo $form->tipo2->value ?>/<?php echo $form->serie->value ?>/<?php echo $form->numero->value ?>', '_blank', 'width=800, height=600, scrollbars=Yes, status=Yes, resizable=Yes, screenx='+((screen.availWidth/2)-400)+',screeny='+((screen.availHeight/2)-300)+'');" heigth="600" >
		<img src='<?php echo base_url() ?>images/pdf_logo.gif'></a> Comprobante 
		</td>
	<?php } ?>
	  <td colspan="3" align="right"><?php echo $container_tr?><?php echo $container_br?></td>
  </tr>
</table>
<table align='center' width="95%">
	<tr>
		<td>
         <table align='center' width="95%">
	<tr>
		<td>
		<table width='100%'><tr><td>
		<fieldset style='border: 2px outset #9AC8DA;background: #FFFFFF;'>
		<legend class="titulofieldset" style='color: #2E4B77;'>Informaci&ograve;n del Pago Realizado </legend>
			<table style="margin: 0; width: 100%;">
			<tr>
				<td class="littletableheader"><?php echo $form->numero->label;    ?></td>
				<td colspan="2" class="littletablerow"><strong><?php echo $form->serie->output;   ?>-<?php echo $form->numero->output;   ?></strong></td>
			</tr>
			<tr>
				<td class="littletableheader"><?php echo $form->fecha->label;    ?></td>
				<td colspan="2" class="littletablerow">   <?php echo $form->fecha->output;   ?></td>
			</tr>
			<tr>
				<td class="littletableheader"><?php echo $form->ccosto->label;    ?></td>
				<td colspan="2" class="littletablerow">   <?php echo $form->ccosto->output;   ?></td>
			</tr>
			<tr>
				<td class="littletableheader"><?php echo $form->cuenta2->label;    ?></td>
				<td colspan="2" class="littletablerow">   <?php echo $form->cuenta2->output;   ?></td>
			</tr>
			<tr>
			  <td class="littletableheader"><?php echo $form->formap->label     ?></td>
			  <td colspan="2" class="littletablerow"><?php echo $form->formap->output    ?></td>
			</tr>
			<tr>
			  <td class="littletableheader"><?php echo $form->referen->label     ?></td>
			  <td colspan="2" class="littletablerow"><?php echo $form->referen->output    ?></td>
			</tr>
			 <tr>
			  <td class="littletableheader"><?php echo $form->tipo2->label     ?></td>
			  <td colspan="2" class="littletablerow"><?php echo $form->tipo2->output    ?></td>
			  </tr>
			 <? IF(($form->tipo2->value=='AN')||($form->tipo2->value=='EC')){?>  
	        <tr>
				<td class="littletableheader"><?php echo $form->cuenta_ori->label;    ?></td>
				<td colspan="2" class="littletablerow">   <?php echo $form->cuenta_ori->output;   ?></td>
			</tr>
			<? } ?>	
			<tr>
			  <td class="littletableheader"><?php echo $form->moneda->label     ?></td>
			  <td colspan="2" class="littletablerow"><?php echo $form->moneda->output    ?></td>
			</tr>
			<tr>
			  <td class="littletableheader"><?php echo $form->cambio->label     ?></td>
			  <td colspan="2" class="littletablerow"><?php echo $form->cambio->output    ?></td>
			</tr>
			</table>
			</fieldset>
		</td><td width="55%">
			<fieldset style='border: 2px outset #9AC8DA;background: #FFFFFF;'>
			<legend  class="titulofieldset" style='color: #2E4B77;'>Identificaci&oacute;n del Proveedor </legend>
			<table  style="margin: 0; width: 100%;">
			<tr>
				<td width="33%" class="littletableheader"><?php echo $form->proveed->label;  ?></td>
				<td class="littletablerow"><?php echo $form->proveed->output; ?></td>
				</tr>
			<tr>
				<td class="littletableheader"><?php echo $form->nombre->label;  ?></td>
				<td class="littletablerow"><?php echo $form->nombre->output;  ?></span></td>
			</tr>
			<tr>
			  <td class="littletableheader"><?php echo $form->rif->label; ?></td>
			  <td class="littletablerow"><?php echo $form->rif->output;   ?></td>
			</tr>
			<tr>
			  <td class="littletableheader"><?php echo $form->cajachica->label; ?></td>
			  <td class="littletablerow"><?php echo $form->cajachica->output;   ?></td>
			</tr>
			<tr>
			  <td class="littletableheader"><?php echo $form->detraccion->label; ?></td>
			  <td class="littletablerow"><?php echo $form->detraccion->output;   ?></td>
			</tr>
			</table>
			</fieldset>
		</td><tr>
	</table>
		<br></td>
	</tr>
	<tr>
		<td>Otros Documentos por Pagar</td>
	</tr>
	<tr>
		<td>
		<div style='overflow:auto;border: 1px solid #9AC8DA;background: #FAFAFA;height:120px'>
		<table width='85%' border='0' align="center">
			<tr id='__INPL__' class="littletablerow">
				<td bgcolor='#6DA7D3'>Documento</td>
				<td bgcolor='#6DA7D3'>Cuenta </td>
				<td bgcolor='#6DA7D3'>Descripci&oacute;n</td>
				<td bgcolor='#6DA7D3'>RUC</td>
				<td bgcolor='#6DA7D3'>Tipo</td>
				<td bgcolor='#6DA7D3' align="center">Monto</td>
				<?php if ($form->_status!='show') { ?>
				<td bgcolor='#527D9E' align="center">Creditos</td>
				<?}?>
				<?php if($form->_status!='show') {?>
					<td class="littletableheader">&nbsp;</td>
				<?php } ?>
			</tr>

			<?php $tot=0; $debitosd=0; $creditosd=0; $tdocd=0; $tdocs=0;for($i=0;$i<$form->max_rel_count['itpprot'];$i++) {
				$it_docu    = "docu_$i";
				$it_cuenta  = "cuenta_$i";
				$it_desca   = "desca_$i";
				$it_ruc     = "ruc_$i";
				$it_tipo    = "tipo_$i";
				$it_importe = "importe_$i";
				$it_creditos= "creditos_$i";
				
				
				$debitosd  +=$form->$it_importe->value;
				$creditosd +=$form->$it_creditos->value;
				$tot=$debitosd-$creditosd;
				
				if($tmoneda=='01'){
					$tdocs=ROUND($tot,2);
				}else{
					$tdocs=ROUND($tot*$tcambio,2);
				}
					
				if($tmoneda=='02'){
					$tdocd=ROUND($tot,2);
				}else{
					$tdocd=ROUND($tot/$tcambio,2);
				}

			?>

			<tr id='tr_itpprot_<?php echo $i; ?>'>
			    <td class="littletablerow" align="left"><?php echo $form->$it_docu->output; ?></td>
				<td class="littletablerow" align="left"><?php echo $form->$it_cuenta->output; ?></td>
				<td class="littletablerow" align="left"><?php echo $form->$it_desca->output;  ?></td>
				<td class="littletablerow" align="left"><?php echo $form->$it_ruc->output;  ?></td>
				<td class="littletablerow" align="center"><?php echo $form->$it_tipo->output;  ?></td>
				<td align="center" class="littletablerow"><?php echo $form->$it_importe->output;   ?></td>
				<?php if ($form->_status!='show') { ?>
				<td class="littletablerow" align="left"><?php echo $form->$it_creditos->output;?></td>
				<?php } ?>
				<?php if($form->_status!='show') {?>
				<td class="littletablerow">
					<a href='#' onclick='del_itpprot(<?=$i ?>);return false;'><?php echo img("images/delete.jpg"); ?></a>				</td>
				<?php } ?>
			</tr>
			<?php } ?>

			<tr id='__UTPL__'>
				<td id='cueca'></td>
			</tr>
			</tr><td class="littletablerow" colspan=7>Total <?=$tot-$creditosd ?></td></tr>
		</table>
		</div>
		<?php echo $container_bl ?>
		</td>
	</tr>
	<tr>
		<td>Facturas Provicionadas</td>
	</tr>
	<tr>
		<td>
		<div style='overflow:auto;border: 1px solid #9AC8DA;background: #FAFAFA;height:150px'>
		  <table width='80%' border='0' align="center">
            <tr class="littletablerow" align="center">
              <td bgcolor='#527D9E'>N&uacute;mero de Factura</td>      
              <td bgcolor='#527D9E'>Moneda Origen</td>  
              <td bgcolor='#527D9E'>Codigo de Proveedor</td>
              <td bgcolor='#527D9E'>Monto Pagado </td>
              <td bgcolor='#527D9E' colspan=2>Conversion </td>
            </tr>
		    <? $tmontos=0; $tmontod=0; $i=0; foreach ($result AS $items){$i++;?>  
            <? $tmontos+=$items->cmontos ?>
            <? $tmontod+=$items->cmontod ?>
            <? $seriefc=$this->datasis->dameval("SELECT seriep FROM sprm WHERE cod_prv='$items->cod_prv' and proveed='$items->proveed' and numero='$items->factura'"); ?> 
            <? $fc=$this->datasis->dameval("SELECT factura FROM sprm WHERE cod_prv='$items->cod_prv' and proveed='$items->proveed' and numero='$items->factura'"); ?> 
            <? $moneda_ori=$this->datasis->dameval("SELECT moneda FROM sprm WHERE cod_prv='$items->cod_prv' and proveed='$items->proveed' and numero='$items->factura'"); ?> 
            <? $nombrep=$this->datasis->dameval("SELECT nombre FROM sprv WHERE  proveed='$items->proveed'"); ?> 
            <tr>
              <td align="left" class="littletablerow"><?=$seriefc?>-<?=$fc?>
              <td align='center' class="littletablerow"><?=$moneda_ori ?></td>
              </td>
			  <td align="left" class="littletablerow"><input type="text"   name="proveedor[]" value="<?=$items->proveed?>" size="7" readonly="false" /><?= $nombrep?></td>
			  <td align='right' class="littletablerow"><?= nformat($items->monto) ?></td> 
			  <td align='right' class="littletablerow">S/.<?=$items->cmontos ?></td>
			  <td align='right' class="littletablerow">US$<?=$items->cmontod ?></td>       
			</tr>
            <? }?>
            <tr>
              <td align='right' class="littletablerow" colspan=4 ><strong>Totales</strong></td>
              <td align='center' class="littletablerow"><strong>S/.<? echo nformat($tmontos) ?></strong></td>
              <td align='center' class="littletablerow"><strong>US$<? echo nformat($tmontod) ?></strong></td> 
            </tr>
          </table>
		</div>
		<?php echo $container_bl ?>		</td>
	</tr>
	<tr>
		<td>
		<fieldset style='border: 2px outset #9AC8DA;background: #EFEFEF;'>
		<legend  class="titulofieldset" style='color: #2E4B77;' align="right">-- Monto Total PAGADO --</legend>
		<table width='100%'>
			<tr>
			  <td width='15%' class="littletableheader"><?php echo $form->condi1->label;    ?></td>
			  <td width='55%'class="littletablerow"   ><?php echo $form->condi1->output;   ?></td>
			  <td width='20%' align='right' class="littletablerow">Total</td>
			  <td width='5%' align='right' class="littletablerow">S/. </td>
			  <td width='5%' align='right' class="littletablerow"><?php echo nformat($tmontos+$tdocs); ?></td>
		  </tr>
		  <tr>
			  <td  class="littletableheader"></td>
			  <td class="littletablerow"   ></td>
			  <td  align='right' class="littletablerow">Total</td>
			  <td  align='right' class="littletablerow">US$</td>
			  <td  align='right' class="littletablerow"><?php echo nformat($tmontod+$tdocd); ?></td>
		  </tr>
		</table>
		</fieldset>	
		</td>
	</tr>
</table>
<?php echo $form_end?>
	  <td>
	<tr>
<table>
</form>
<?php endif; ?>
